﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wasion.HHU.Data.Models;
using Windows.Storage;

namespace Wasion.HHU.Data
{
    public static class Init
    {
        public static async Task InitDbAsync()
        {
            var dbFile = await ApplicationData.Current.LocalFolder.TryGetItemAsync("hhu.db") as StorageFile;

            if (null == dbFile)
            {
                // first time ... copy the .db file from assets to local  folder
                var localFolder = ApplicationData.Current.LocalFolder;
                var originalDbFileUri = new Uri("ms-appx:///Assets/hhu.db");
                var originalDbFile = await StorageFile.GetFileFromApplicationUriAsync(originalDbFileUri);

                if (null != originalDbFile)
                {
                    dbFile = await originalDbFile.CopyAsync(localFolder, "hhu.db", NameCollisionOption.ReplaceExisting);
                }
            }

            //using (var db = new DbConn().Connection)
            //{
            //    //db.CreateTable<User>();
            //    //db.CreateTable<UserRole>();
            //    //db.CreateTable<Schema>();
            //    //db.CreateTable<SchemaItem>();
            //    //db.CreateTable<SchemaItemPar>();
            //    //db.Insert(new User() { Level = LevelType.Beginner,Name = "abc",PassWord = "202cb962ac59075b964b07152d234b70" });//password:123

            //    //db.Insert(new Schema() { ID = "24ec91ed-3954-4023-9d1f-f6d684d75900", SchName = "test", DateModified = DateTime.Now.ToString(), SchemaDesc = "测试方案", SchType = 0 });
            //    //db.Insert(new SchemaItem()
            //    //{
            //    //    ID = "d4835ff5-b0bc-4539-adae-2fdc735015ed",
            //    //    PID = "",
            //    //    ObAttrMthID = "255e1c9f-dc5e-406e-8319-aa9648c76842",
            //    //    SchID = "24ec91ed-3954-4023-9d1f-f6d684d75900",
            //    //    SNO = 2
            //    //});
            //    //db.Insert(new SchemaItem()
            //    //{
            //    //    ID = "4e8a829d-94ae-4fe5-a97a-eb818626d4d3",
            //    //    PID = "",
            //    //    ObAttrMthID = "4d65f8e2-74f5-4bc3-b0e0-7437965325ec",
            //    //    SchID = "24ec91ed-3954-4023-9d1f-f6d684d75900",
            //    //    SNO = 2
            //    //});
            //    //db.Insert(new SchemaItem()
            //    //{
            //    //    ID = "72fd2a74-6f9a-4fac-b5c3-d7902d9e0c3a",
            //    //    PID = "",
            //    //    ObAttrMthID = "d5293599-6370-46eb-ba03-4a846dabf732",
            //    //    SchID = "24ec91ed-3954-4023-9d1f-f6d684d75900",
            //    //    SNO = 2
            //    //});
            //    //db.Insert(new SchemaItem()
            //    //{
            //    //    ID = "c6f30d6c-c182-44a3-9ebb-9ab723567634",
            //    //    PID = "",
            //    //    ObAttrMthID = "0e1576f5-1f1b-4b62-83cf-f60d8214aa57",
            //    //    SchID = "24ec91ed-3954-4023-9d1f-f6d684d75900",
            //    //    SNO = 2
            //    //});

            //}
        }
    }
}
